/** 
* All Rights Reserved , Copyright (C) 2020 , 青岛鼎信通讯股份有限公司
* 
* PmResourceApplyLineService
* 资源申请明细
* 
* 修改纪录
* 2020-05-13 版本：1.0 shenyouyi 创建。
* @version 版本：1.0
* @author 作者：shenyouyi
* 创建日期：2020-05-13
*/
package com.topscomm.pm.service.impl;

import com.topscomm.basic.BasicEntity;
import com.topscomm.basic.exception.BusinessException;
import com.topscomm.basic.exception.ServiceException;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.StringBufferProxy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.topscomm.pm.pojo.PmResourceApplyLineEntity;
import com.topscomm.pm.service.IPmResourceApplyLineService;
import com.topscomm.pm.service.impl.auto.PmResourceApplyLineServiceAuto;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service(value = "pmResourceApplyLineService")
@Scope(value = "singleton")
public class PmResourceApplyLineService extends PmResourceApplyLineServiceAuto implements IPmResourceApplyLineService {

    /**
     * 重写beforeInsert方法，设置行号
     * @param entity
     * @throws ServiceException
     */
    @Override
    protected void beforeInsert(BasicEntity entity) throws ServiceException {
        super.beforeInsert(entity);        
        String resourceapplyid = entity.getValue("resourceapplyid").toString();
    	// 需要校验变更的资源明细是否存在于其他的变更单(开立和正在审核)中（不允许存在于其他变更单中）
//        if (entity.()) {
//			
//		}

//        pmResourceApplyService.queryById(resou)
        StringBufferProxy sql = new StringBufferProxy();
        sql.appendSingle("resourceapplyid = {0}", resourceapplyid);
        List<String> listFields = new ArrayList<>();
        listFields.add("max(lineno) as maxLineno");
        List<Map<String,Object>> queryResultList = this.queryMapFieldsByWhere(sql.toString(), listFields);
        Long maxLineno = 0L;
        if(queryResultList.size()>0&&queryResultList.get(0)!=null&&queryResultList.get(0).get("maxLineno")!=null){
            maxLineno = Long.valueOf(queryResultList.get(0).get("maxLineno").toString());
        }
        entity.setValue("lineno", maxLineno + 1);
    }

}
